package com.lwy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lwy.dao.BookCategoryMapper;
import com.lwy.entity.BookCategory;
import com.lwy.entity.ResoucesInfo;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

//小说分类service接口实现类
@Service
public class BookCategoryServiceImpl extends ServiceImpl<BookCategoryMapper, BookCategory> {


    public List<BookCategory> list(){
        List<BookCategory> bookCategories = baseMapper.selectList(new QueryWrapper<BookCategory>().gt("parentid",0));
        List<BookCategory> bookCategories2 = baseMapper.selectList(new QueryWrapper<BookCategory>().eq("parentid",0));

        for (BookCategory bookCategory : bookCategories2) {
            List<BookCategory> list = new ArrayList<>();
            for (BookCategory category : bookCategories) {
                if(bookCategory.getId()==category.getParentid()){
                    list.add(category);
                }
            }
            bookCategory.setList(list);
        }
        return bookCategories2;
    }

    public List<BookCategory> findList(){
        List<BookCategory> bookCategories = baseMapper.selectList(new QueryWrapper<BookCategory>().gt("parentid",0));
        List<BookCategory> bookCategories2 = baseMapper.selectList(new QueryWrapper<BookCategory>().eq("parentid",0));
        List<BookCategory> list = new ArrayList<>();
        for (BookCategory bookCategory : bookCategories2) {
            for (BookCategory category : bookCategories) {
                if(bookCategory.getId()==category.getParentid()){
                    list.add(category);
                }
            }
        }
        return list;
    }
}
